package com.library.web.controller.app;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.library.common.annotation.Log;
import com.library.common.core.controller.BaseController;
import com.library.common.core.domain.AjaxResult;
import com.library.common.core.page.TableDataInfo;
import com.library.common.enums.BusinessType;
import com.library.common.utils.poi.ExcelUtil;
import com.library.domain.AppActivityType;
import com.library.framework.manager.BizCodeManager;
import com.library.service.IAppActivityTypeService;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 活动类型Controller
 *
 * @author ruoyi
 * @date 2022-03-25
 */
@RestController
@RequestMapping("/app/activityType")
public class AppActivityTypeController extends BaseController {
    @Autowired
    private IAppActivityTypeService appActivityTypeService;
    @Autowired
    private BizCodeManager bizCodeManager;

    /**
     * 查询活动类型列表
     */
    @PreAuthorize("@ss.hasPermi('app:activityType:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppActivityType appActivityType) {
        startPage();
        List<AppActivityType> list = appActivityTypeService.selectAppActivityTypeList(appActivityType);
        return getDataTable(list);
    }

    /**
     * 获取全部分类
     *
     * @return
     */
    @GetMapping("/selectAll")
    public AjaxResult selectAll() {
        List<AppActivityType> appActivityTypes = appActivityTypeService.selectAppActivityTypeList(new AppActivityType());
        List<Map<String, String>> mapList = new ArrayList<>();
        appActivityTypes.forEach(appActivityType -> {
            Map<String, String> stringMap = new HashMap<>(appActivityTypes.size());
            stringMap.put("id", appActivityType.getActivityTypeId().toString());
            stringMap.put("no", appActivityType.getActivityTypeNo());
            stringMap.put("name", appActivityType.getActivityTypeName());
            mapList.add(stringMap);
        });
        return AjaxResult.success(mapList);
    }

    /**
     * 导出活动类型列表
     */
    @PreAuthorize("@ss.hasPermi('app:activityType:export')")
    @Log(title = "活动类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppActivityType appActivityType) {
        List<AppActivityType> list = appActivityTypeService.selectAppActivityTypeList(appActivityType);
        ExcelUtil<AppActivityType> util = new ExcelUtil<AppActivityType>(AppActivityType.class);
        util.exportExcel(response, list, "活动类型数据");
    }

    /**
     * 获取活动类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:activityType:query')")
    @GetMapping(value = "/{activityTypeId}")
    public AjaxResult getInfo(@PathVariable("activityTypeId") Long activityTypeId) {
        return AjaxResult.success(appActivityTypeService.selectAppActivityTypeByActivityTypeId(activityTypeId));
    }

    /**
     * 新增活动类型
     */
    @PreAuthorize("@ss.hasPermi('app:activityType:add')")
    @Log(title = "活动类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppActivityType appActivityType) {
        appActivityType.setActivityTypeNo(bizCodeManager.createAt());
        return toAjax(appActivityTypeService.insertAppActivityType(appActivityType));
    }

    /**
     * 修改活动类型
     */
    @PreAuthorize("@ss.hasPermi('app:activityType:edit')")
    @Log(title = "活动类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppActivityType appActivityType) {
        return toAjax(appActivityTypeService.updateAppActivityType(appActivityType));
    }

    /**
     * 删除活动类型
     */
    @PreAuthorize("@ss.hasPermi('app:activityType:remove')")
    @Log(title = "活动类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{activityTypeIds}")
    public AjaxResult remove(@PathVariable Long[] activityTypeIds) {
        return toAjax(appActivityTypeService.deleteAppActivityTypeByActivityTypeIds(activityTypeIds));
    }
}
